<?php

class Core_Model_Customer_Showroom extends Dcmp_Model_Status {

    public function __construct() {
        parent::__construct();
    }

    public function getPoi(){
        if(!$this->hasData('poi')){
            if($this->issetData('poi_id')){
                $this->data['poi'] = App::getModel('foundation/poi')->load($this->getPoiId());
            }
        }
        return $this->data['poi'];
    }
    
    public function getCertificates(){
    	return App::getModel('customer/collection_showroom_certificate')
    				->filterByShowroomId($this->getId());
    }
    
    public function updateClickCount(){
        Kd_Data_Factory::getUpdateDcl()
                ->into($this->getTable()->getName())
                ->value('click_count', Kd_Data_Dcl_Fn::addition('click_count', 1))
                ->where()->eq('id', ':id:i')->closest()
                ->addParameter('id', $this->getId())
                ->execute();
        return $this;
    }    

    protected function initializeTable($table) {
        $table->setName('{t}customer_showroom');
        $table->createColumn('id', 'integer', TRUE, TRUE);
        $table->createColumn('name', 'string');
        $table->createColumn('introduction', 'string');
        $table->createColumn('sd_url', 'string');
        $table->createColumn('hd_url', 'string');
        $table->createColumn('preview_image', 'string');
        $table->createColumn('click_count', 'integer')->setDefaultValue(0);
        $table->createColumn('poi_id', 'string')->setUpdateable(FALSE);
        parent::initializeTable($table);
    }

}